package org.neptune.service.config;

import org.apache.shiro.cache.AbstractCacheManager;
import org.apache.shiro.cache.Cache;
import org.apache.shiro.cache.CacheException;
import org.neptune.common.constant.NeptuneConstant;
import org.neptune.service.cache.ShiroRedisCache;
import org.neptune.service.redis.RedisRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ShiroRedisCacheManager extends AbstractCacheManager {

	private static Logger logger = LoggerFactory.getLogger(ShiroRedisCache.class);

	private RedisRepository redisRepository;

	private NeptuneConfig neptuneConfig;

	public ShiroRedisCacheManager(RedisRepository redisRepository) {
		this.redisRepository = redisRepository;
	}

	public ShiroRedisCacheManager(RedisRepository redisRepository, NeptuneConfig neptuneConfig) {
		this.redisRepository = redisRepository;
		this.neptuneConfig = neptuneConfig;
	}

	@SuppressWarnings("rawtypes")
	@Override
	protected Cache createCache(String name) throws CacheException {

		logger.info("shiro redis cache manager name : " + name);

		return new ShiroRedisCache(redisRepository, NeptuneConstant.REDIS_SHIRO_SESSION_CACHE,
				neptuneConfig.loginSessionCachetime);
	}
}